const app = getApp()

import {
  search
} from '../../../api/blog'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    emptyData: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    this.setData({
      handleSearch: this.handleSearch.bind(this)
    })
  },


  // 搜索方法
  handleSearch(value) {
    return new Promise((resolve, reject) => {
      search(value).then(res => {
        if (res.code === 200) {
          let list = res.data.list
          this.setData({
            emptyData: this.data.emptyData = list.length === 0
          })
          resolve(list)
        } else {
          app.showToast(res.msg)
          reject(res.msg)
        }
      })
    })
  },
  // 点击搜索结果
  selectResult(e) {
    let akey = e.detail.item.value
    wx.navigateTo({
      url: '../detail/detail?akey=' + akey,
    })
  },



})